package com.rr.easy;

import java.util.Arrays;

/**
 * @author zhuangcanrun
 * @Date 2022/05/10/22:21
 * @description
 **/

/*
 *https://leetcode.cn/problems/maximum-product-of-three-numbers/
 * */
public class MaximumProduct {
    public int maximumProduct(int[] nums) {
        int length = nums.length;
        if (length == 3) {
            return nums[0] * nums[1] * nums[2];
        }

        Arrays.sort(nums);
        int ans1 = nums[length - 1] * nums[length - 2] * nums[length - 3];
        int ans2 = nums[length - 1] * nums[1] * nums[0];
        return Math.max(ans1, ans2);
    }
}
